package com.googlecode.project4uz.encoder;

import java.beans.Expression;
import java.beans.Statement;
import java.io.OutputStream;

import org.openrdf.rio.RDFFormat;


import edu.uz.issilab.rdfserializer.interfaces.RDFEncodeable;

/**
 * Pozwala na plytka lub beansowa serializacje obiektów
 * do strumienia znakowego w kilku formatach RDF.
 * @author Daniel Kur
 * @see edu.uz.issilab.rdfserializer.interfaces.RDFEncodeable
 */
public class RDFEncoder implements RDFEncodeable {
	/**
	 * Analizuje obiekty przeslane do strumienia.
	 */
	private final AbstractSerializer serializer;
	
	/**
	 * Tworzy obiekt kodera obiektow do formatu RDF.
	 * @param format - format RDF jakim zapisujemy do strumienia.
	 * @param type - sposob serializacji obiektu.
	 * @param output - strumien wyjsciowy dla wyniku.
	 */
	public RDFEncoder(final RDFFormat format, final Serializer type, final OutputStream output) {
		this.serializer = AbstractSerializer.createSerializer(type.getInstance(format, output));
	}

	/**
	 * @see edu.uz.issilab.rdfserializer.interfaces.RDFEncodeable#getOwner()
	 */
	public Object getOwner() {
		return serializer.getOwner();
	}

	/**
	 * @see edu.uz.issilab.rdfserializer.interfaces.RDFEncodeable#setOwner(Object owner)
	 */
	public void setOwner(final Object owner) {
		this.serializer.setOwner(owner);
	}

	/**
	 * @see edu.uz.issilab.rdfserializer.interfaces.RDFEncodeable#writeObject(Object o)
	 */
	public void writeObject(final Object o) {
		this.serializer.readObject(o);
	}

	/**
	 * @see edu.uz.issilab.rdfserializer.interfaces.RDFEncodeable#writeStatement(Statement oldStm)
	 */
	public void writeStatement(final java.beans.Statement oldStm) {
		this.serializer.readStatement(oldStm);
	}

	/**
	 * @see edu.uz.issilab.rdfserializer.interfaces.RDFEncodeable#writeExpression(Expression oldExp)
	 */
	public void writeExpression(final java.beans.Expression oldExp) {
		this.serializer.readExpression(oldExp);
	}
	
	/**
	 * Dopisuje komentarz w formacie RDF do strumienia.
	 * @param comment - tresc komentarza.
	 */
	public void writeComment(final String comment) {
		this.serializer.writeComment(comment);
	}

	/**
	 * @see edu.uz.issilab.rdfserializer.interfaces.RDFEncodeable#flush()
	 */
	public void flush() {
		this.serializer.flush();
	}

	/**
	 * @see edu.uz.issilab.rdfserializer.interfaces.RDFEncodeable#close()
	 */
	public void close() {
		this.serializer.close();
	}
}
